real(8), allocatable, dimension(:, :) :: x, y, z
real(8), allocatable, dimension(:,:,:) :: q
integer :: in, jn, kn, ln

open(999, file='xsyszs.grd', iostat=ios, status="old", action="read", form='unformatted')
if ( ios /= 0 ) stop "Error opening file Grid.xyz"
read(999)
read(999)in, jn, kn
print*, in, jn, kn
allocate(x(in, jn))
allocate(y(in, jn))
read(999)x, y
close(999)

open(999, file='xsyszs_1.grd', form='unformatted')
write(999)1
write(999)in, jn
write(999)x, y
close(999)


open(999, file='301-501-new.dat', iostat=ios, status="old", action="read", form='unformatted')
if ( ios /= 0 ) stop "Error opening file Grid.xyz"
read(999)
read(999)in, jn, kn, ln
print*, in, jn, ln
allocate(q(in, jn, ln))
read(999)q
close(999)

open(1000, file='301-501-new_1.dat', form='unformatted')
write(1000)1
write(1000)in, jn, ln
print*, in, jn, ln
write(1000)q
close(1000)

end
